<?php
namespace Core\Extensions\Modules\Er\Controllers\EngenhariaReversa;

use Core\Libs\CreateFile\CreateFile;

class EngenhariaReversa extends \Core\Extensions\Modules\Er\Controllers\ExtendController\ExtendController {
	
	public function view()
	{
		
	}
	
	public function index()
	{
		/*
		//$driver = null, $user = null, $password = null, $server = null
		if($_GET['driver'] && $_GET['user'] && $_GET['server'])
		{
			
			$this->dbAjax();
		}
		*/
	}
	public function create()
	{
		
	}
	public function add() 
	{
		
	//print_r($this->getData());
		
	$typeDB = $_POST["driver"];
	$DBname = 'tcc';//$_POST["db"];
	$projectName = $_POST['project'];
	$DBuser = $_POST['user'];
	$DBserver = $_POST['server'];
	$DBpassword = $_POST['password'];
	
	$model = $_POST['model'];
	$view = $_POST['view'];
	$controller = $_POST['controller'];
	
	/*if($_GET['driver'] && $_GET['user'] && $_GET['server'])
	{
		
		$this->dbAjax();
	}
	*/
	//$cf = new CreateFile();
	
	//$cf->Create($typeDB, $DBuser, $DBpassword, $DBname, $DBserver, $projectName, $model, $view, $controller);
		
		//echo "teste - ".$_POST['project'];
		//\Core\Libs\CreateFile\CreateFile->Create($typeDB, $DBuser, $DBpassword, $DBname, $DBserver, $projectName, $model, $view, $controller);   //::teste(); //::teste();
		//\Core\Libs\CreateFile\CreateFile Cf; //= new \Core\Libs\CreateFile\CreateFile();
		//CreateFile cf = new CreateFile();
		//CreateFile cf = new CreateFile();
		//\CreateFile cf = new \CreateFile();  //\ReflectionFunction($_function);
		
		
		//CreateFile cf = new CreateFile();
		//$this->getRegistry()->getClass('Core.Libs.CreateFile');
		
		
	 	//CreateFile cf = new \CreateFile();
		
	 	$cf = new \Core\Libs\CreateFile\CreateFile();
	 	
	 	//$cf->Create($typeDB, $DBuser, $DBpassword, $DBname, $DBserver, $projectName, $model, $view, $controller);
	 	$cf->Create($this->getData());
	 	
		//echo "<script>window.top.location = 'http://localhost/Core.Module.er.EngenhariaReversa/index'</script>";
		//\Core\Libs\CreateFile\CreateFile::Create($typeDB, $DBuser, $DBpassword, $DBname, $DBserver, $projectName, $model, $view, $controller);   //::teste(); //::teste();
	}
	public function dbAjax()
	{
		$driver = $_GET['driver'];
		$user = $_GET['user'];
		$server = $_GET['server'];
		//$password = $_GET['password'];
		//$password = '';
		//$driver = 'mysql';
		//$user = 'root';
		//$server = 'localhost';
		
		
		switch($driver){
			case 'mysql';
				mysql_connect($server,$user,$password);
				//mysql_selectdb('combobox');
				$result = mysql_query("SHOW DATABASES");
				while($row = mysql_fetch_array($result) ){
				    echo "<option value='".$row['Database']."'>".$row['Database']."</option>";
				}
				break;
			case 'sqlserver';
				//PAULORAFAEL-PC\SQLEXPRESS
				$conn = new PDO("mssql:host=$server;dbname='', $user, $password");
				$result = $conn->prepare("SELECT * FROM sys.databases");
				foreach ($result as $row){
				   	echo "<option value='".$row['datname']."'>".$row['datname']."</option>";
				}
				break;
				
			case 'postegres';
				//mysql_connect($server,$user,$password);
				$conn = new PDO("pgsql:dbname='';host=".$server, $user, $password );
				$result = $conn->query("SELECT datname FROM pg_database");
				
				while($row = $result){
				   	echo "<option value='".$row['datname']."'>".$row['datname']."</option>";
				}
				break;
			
		}
	}
	
}
?>